<template>
  <ul class="tabs" :class="{[classPrefix+'-tabs']:classPrefix,}">
    <li v-for="item in dataSource" :key="item.value"
        :class="liClass(item)"
        @click="select(item)">{{ item.text }}
    </li>
  </ul>
</template>

<script lang="ts">
import Vue from 'vue';
import {Component, Prop} from 'vue-property-decorator';

type DataSourceItem = { text: string, value: string }
@Component
export default class Tabs extends Vue {
  @Prop({required: true, type: Array})
  dataSource!: { text: string, value: string }[];
  @Prop(String)
  readonly value!: string;
  @Prop(String)
  classPrefix?: string;

  liClass(item:DataSourceItem){
    return {[this.classPrefix + '-tabs-item']: this.classPrefix, selected: item.value === this.value};
  }

  select(item: DataSourceItem) {
    this.$emit('update:value', item.value);
  }
}
</script>

<style lang="scss" scoped>
@import "~@/assets/styles/helper.scss";

.tabs {
  display: flex;
  font-size: 24px;

  > li {
    border-top: 1px solid #ccc;
    background-color: #f5f5f5;
    position: relative;
    height: 64px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-grow: 1;
    font-weight: 600;

    &.selected {
      color: $themeColor;
      background-color: white;

      &::after {
        position: absolute;
        content: '';
        display: block;
        height: 5px;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 2rem;
        background-color: $themeColor;
      }

    }
  }
}
</style>
